package com.prs.crm.service.doc.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.AppContext;
import com.prs.crm.context.FileUtil;
import com.prs.crm.dao.doc.UserDocDao;
import com.prs.crm.domain.doc.DocType;
import com.prs.crm.domain.doc.UserDoc;
import com.prs.crm.service.doc.UserDocService;
import com.prs.crm.service.impl.BaseServiceImpl;

public class UserDocServiceImpl extends BaseServiceImpl<UserDoc,UserDocDao> implements UserDocService{

	@Override
	public void saveUserDoc(UserDoc userDoc, File file, String fileName) {
		// TODO Auto-generated method stub
		userDoc.setAttach(FileUtil.getInstance().createAttach(file, fileName));
		userDoc.setRecorder(AppContext.getAccountContext().currentUser());
		userDoc.setRecordTime(new Date());
		this.getDao().save(userDoc);
	}

	@Override
	public Collection<DocType> convertToDocType(String ids) {
		// TODO Auto-generated method stub
		Collection<DocType> types = new ArrayList<DocType>();
		for(String id : ids.split(",")) {
			DocType type = new DocType();
			type.setId(Integer.valueOf(id));
			types.add(type);
		}
		return types;
	}

}
